This invention relates in general to scanning documents for use with an optical character recognition (OCR) software program and in particular to deskewing an image containing text.
It is well known that documents containing text may be scanned using a flatbed scanner or rotary-type scanner to produce a digitized image of the document. If the document contains text, an optical character recognition (OCR) software program may be used to decipher the text contained in the scanned document. This process allows typed documents to be modified without having to be retyped.
A problem that is often encountered is that the document being scanned is skewed at an angle to the scanner, i.e., the document may be oriented at an angle on the flatbed scanner, or the paper containing the document may be fed at an angle on a high speed scanner with an automatic sheet feed. These skewed images are unattractive when displayed onscreen and, more important, may affect the accuracy of OCR software programs designed to decipher the text contained in the document.
Prior art attempts to solve this problem have required the user of the software program to construct a line onscreen with a pointing device, which matches the angle of skew of the lines in the document. The user then invokes a software program which straightens the line drawn onscreen and hence, the remaining lines of text in the document. This method, however, involves active participation of the user, and is relatively slow. It is desirable to have a software program which automatically checks and corrects the skew angle of scanned documents.
It is an object of the invention to provide a method for automatically deskewing a text image. The present invention is directed to overcoming one or more of the problems set forth above.
The above and other objects are accomplished by a method for deskewing a text image. Briefly summarized according to one aspect of the present invention the method comprises the steps of:
a) determining a first intensity level for each line of a scanned image, with the image in an original position;
b) determining which of the lines has a highest intensity level and which of the lines has a lowest intensity level;
c) adding a relaxation factor to the lowest intensity level to establish a lower threshold;
d) subtracting the relaxation factor from the highest intensity level to establish an upper threshold;
e) determining a first value equal to a sum of lines having a first intensity level above the upper threshold and lines having a first intensity level below the lower threshold;
f) rotating the image by a first amount in a first direction to a first position;
g) determining a second intensity level for each line of the rotated image;
h) determining a second value equal to a sum of lines having a second intensity level above the upper threshold and lines having a second intensity level below said lower threshold;
i) rotating said image by a second amount in a second direction to a second position;
j) determining a third intensity level for each line of the rotated image;
k) determining a third value equal to a sum of lines having a third intensity level above the upper threshold and lines having a third intensity level below the lower threshold for said rotated image;
l) if the first value is greater than the second value or the third value, rotate the image to the original position and exit program, if not proceed to step m;
m) determining if the first amount is greater than a granularity factor, if yes, go to step n, if not rotate the image to the original position and exit program;
n) determining whether the first value or the second value is greater and set the position associated with the greater value as the original position;
o) setting the first amount to one half of previous value;
p) setting the second amount to one half of previous value; and
q) returning to step e.
In one embodiment of the invention, the first amount and second amount are six degrees. In another embodiment, the granularity factor is one degree. In yet another embodiment, the relaxation factor is 10 percent.
The above, and other objects, advantages and novel features of the present invention will become more apparent from the accompanying detailed description thereof when considered in conjunction with the following drawings.